package com.example.cstr.controller;

import com.example.cstr.entity.Message;
import com.example.cstr.entity.StudyContain;
import com.example.cstr.service.StudyContainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;

@RestController
@RequestMapping("/api/StudyContain")
@Api(tags = "学习内容")
public class StudyContainController {
    @Resource
    private StudyContainService studyContainService;

    @ApiOperation(value = "添加学习内容")
    @PostMapping("/add")
    public Message insertStudyContain(StudyContain studyContain){
        return studyContainService.insertSelective(studyContain)>0?Message.success(null).add(studyContain.getScId()):Message.fail(null);
    }

    @ApiOperation(value = "删除学习内容")
    @DeleteMapping("/delete")
    public Message deleteStudyContain(Integer scId){
        return studyContainService.deleteByPrimaryKey(scId)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "修改学习内容")
    @PutMapping("/update")
    public Message updateStudyContain(StudyContain studyContain){
        return studyContainService.updateByPrimaryKeySelective(studyContain)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value="根据学习内容id查询学习内容信息")
    @GetMapping("/select")
    public Message selectStudyContain(Integer scId){
        return studyContainService.selectByPrimaryKey(scId)!=null?Message.success(null).add(studyContainService.selectByPrimaryKey(scId)):Message.fail(null);
    }

    @ApiOperation(value = "查询所有学习内容信息")
    @GetMapping("/selectall")
    public Message selectAllStudyContain(){
        return Message.success(null).add(studyContainService.selectAllStudyContain());
    }

    @ApiOperation(value = "分页查询-查询所有学习内容信息")
    @GetMapping("/pagingSearch")
    public Message PagingSearch(@RequestParam Integer pageNum,@RequestParam Integer size){
        return studyContainService.PagingSearch(pageNum,size);
    }

    @ApiOperation(value = "根据用户workid和教育培训项目id查询其学习内容信息")
    @GetMapping("/selectBySc_work_idAndSc_etp_id")
    public Message selectBySc_work_idAndSc_etp_id(Integer sc_work_id,Integer sc_etp_id){
        return studyContainService.selectBySc_work_idAndSc_etp_id(sc_work_id,sc_etp_id)!=null?Message.success(null).add(studyContainService.selectBySc_work_idAndSc_etp_id(sc_work_id,sc_etp_id)):Message.fail(null);
    }

    @ApiOperation(value = "通过教育培训类别id和教育培训项目id查询学习内容信息")
    @GetMapping("/selectBySc_etc_idAndSc_etp_id")
    public Message selectBySc_etc_idAndSc_etp_id(Integer sc_etc_id,Integer sc_etp_id){
        return studyContainService.selectBySc_etc_idAndSc_etp_id(sc_etc_id,sc_etp_id)!=null?Message.success(null).add(studyContainService.selectBySc_etc_idAndSc_etp_id(sc_etc_id,sc_etp_id)):Message.fail(null);
    }

    @ApiOperation(value = "分页查询-根据用户workid和教育培训项目id查询其学习内容信息")
    @GetMapping("/pagingSearch_BySc_work_idAndSc_etp_id")
    public Message pagingSearch_BySc_work_idAndSc_etp_id(@RequestParam Integer pageNum, @RequestParam Integer size, Integer sc_work_id, Integer sc_etp_id){
        return studyContainService.pagingSearch_BySc_work_idAndSc_etp_id(pageNum,size,sc_work_id,sc_etp_id);
    }

    @ApiOperation(value = "word导出")
    @GetMapping("/word")
    public Message getWord(Integer workId) throws IOException {
        return studyContainService.getWord(workId);
    }
}
